﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain;
using Service.Interface;
using Dao.Interface;

namespace Service
{
    public class MemoService : Service<Memo>, IMemoService
    {
        /// <summary>
        /// 获取备忘录分页集合
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageCount">总页数</param>
        /// <param name="delete">是否删除</param>
        /// <returns></returns>
        public IList<Memo> LoadAllMemoByPage(int userID, int pageIndex, int pageSize, out int pageCount, bool delete)
        {
            return ((IMemoRepository)(this.CurrentRepository)).LoadAllMemoByPage(userID, pageIndex, pageSize, out pageCount, delete).ToList();
        }

        /// <summary>
        /// 更新备忘录是否扔进垃圾箱
        /// </summary>
        /// <param name="memoID">备忘录ID</param>
        /// <param name="delete">是否删除</param>
        public void UpdateMemoMarkDelete(object memoID, bool delete)
        {
            if (memoID == null)
            {
                return;
            }
            Memo memo = ((IMemoRepository)(this.CurrentRepository)).Get(memoID);
            memo.MarkDelete = delete;
            ((IMemoRepository)(this.CurrentRepository)).Update(memo);
        }

        /// <summary>
        /// 获取备忘录集合
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="delete">是否删除</param>
        /// <returns></returns>
        public IList<Memo> LoadAllMemo(object userID, bool delete)
        {
            if (userID == null)
            {
                return null;
            }
            return ((IMemoRepository)(this.CurrentRepository)).LoadAllMemo(userID, delete);
        }

        /// <summary>
        /// 获取需要提醒的备忘录
        /// </summary>
        /// <returns></returns>
        public IList<Memo> LoadAllWarnMemo()
        {
            IList<Memo> memoList = ((IMemoRepository)(this.CurrentRepository)).LoadAll()
                .Where(t => t.WarnTime > DateTime.Now && t.WarnTime <= DateTime.Now.AddMinutes(30)
                    && t.MarkDelete == false && (t.SendEmail == true || t.SendMobileMessage == true)).ToList();
            return memoList;
        }
    }
}
